#ifndef SNAKE_H
#define SNAKE_H

#include <QWidget>
#include <QPainter>
#include <QFontMetrics>
#include <QTime>
#include <QKeyEvent>
#include <QDir>

QT_BEGIN_NAMESPACE
namespace Ui {
class Snake;
}
QT_END_NAMESPACE

class Snake : public QWidget
{
    Q_OBJECT

public:
    Snake(QWidget *parent = nullptr);
    ~Snake();

protected:
    void paintEvent(QPaintEvent *); // t
    void timerEvent(QTimerEvent *);
    void keyPressEvent(QKeyEvent *);

private:
    QImage dot;
    QImage head;
    QImage apple;

    static const int B_WIDTH = 300;
    static const int B_HEIGHT = 300;
    static const int DOT_SIZE = 10;
    static const int ALL_DOTS = 900;
    static const int RAND_POS = 29;
    static const int DELAY = 140;

    int timerID;
    int dots;
    int apple_x;
    int apple_y;

    int x[ALL_DOTS];
    int y[ALL_DOTS];

    bool leftDirection;
    bool rightDirection;
    bool upDirection;
    bool downDirection;
    bool inGame;

    void loadImages(); // t
    void initGame(); // t
    void locateApple(); // t
    void checkApple(); // t
    void checkCollision(); // t
    void move(); // t
    void doDrawing(); // t
    void gameOver(QPainter &); // t

private:
    Ui::Snake *ui;
};
#endif // SNAKE_H
